$(function () {



    //==============================搜索按钮
    $("#bzjyj_toolbar [name='searchButton']").click(function () {
        bzjyj_search();
    });
    function bzjyj_search() {

        $(grid).datagrid({
            queryParams: {
                htbm: $("#bzjyj_toolbar [name='htbm']").val()
            }});
    };

//======================
//========统计列表========
//======================

    var columns = [
        [

            {field: 'id', title: 'id', hidden: true, width: 100},
            {field: 'cght_htbm', title: '合同号', width: 100, align: 'center'},
            {field: 'pgzsbl', title: '普钢指数涨幅', width: 100, align: 'center', formatter: function (v) {
                return formatJe2(v * 10000 / 10000 * 100) + '%'
            }},
            {field: 'bzjbl', title: '保证金输入比例', width: 100, align: 'center', formatter: function (v) {
                return formatJe2(v * 10000 / 10000) + '%'
            }},
            {field: 'dqbzjbl', title: '当前实际保证金比例', width: 100, align: 'center', formatter: function (v) {
                return formatJe2(v * 10000 / 10000 * 100) + '%'
            }},
            {field: 'zt', title: '保证金预警状态',
                formatter: function (value, row) {
                    if (value == "追加保证金或者提货") {
                        return  "<a title='点击查看详细'style='color:red;font-weight:bold;' href='javascript:bzjyj_detail(" + row.id + ");'>" + value + "</a>";
                    } else {
                        return  "<a title='点击查看详细'style='color:blue;font-weight:bold;' href='javascript:bzjyj_detail(" + row.id + ");'>" + value + "</a>";
                    }
                }, width: 100, align: 'center'}
        ]
    ];

    var grid = $('#bzjyj_grid').datagrid({
        url: $.webPath() + '/tjbb/bzjyj/bzjyjcList',
        toolbar: "#bzjyj_toolbar",
        striped: true,
        pagination: true,
        pageSize: 10,
        rownumbers: true,
        singleSelect: true,
        collapsible: true,
        fit: true,
        pageNumber: 1,
        fitColumns: true,
        showFooter: true,
//        loadFilter: function (data) {
//            $.each(data.rows, function () {
//                if (this.pgzsbl && parseFloat(this.pgzsbl) < 0) {//如果普钢指数相对值高于于基准值5%必须追加保证金
//                    var p = Math.abs(parseFloat(this.pgzsbl));
//                    if(p.toFixed(2) > 0.05){
//                        this.zt = "追加保证金";
//                    }
//                }
//                if (parseFloat(this.pgzsbl) + parseFloat(this.dqbzjbl) + 0.02 <= parseFloat(this.bzjbl) / 100) {
//                    this.zt = "追加保证金";
//                }
//            })
//
//            return data;
//        },
        onLoadSuccess: function () {
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        },
        columns: columns
    });


});
// 查看入库明细
function bzjyj_detail(id) {
    var button
    button = [
    ];
    $.window({
        title: "保证金预警详细",
        iconCls: 'icon-tip',
        url: $.webPath() + "/tjbb/bzjyj/bzjyj_detail?id=" + id,
        width: 800,
        height: 415,
        buttons: button
    });
}